package shiro.sso.chapter01.intercer;

import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyInterceptor implements HandlerInterceptor {


    //在请求处理之前进行调用（Controller方法调用之前
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {

        Enumeration<String> en = httpServletRequest.getParameterNames();
        Map<String, Object> extraParams = new HashMap<String, Object>();
        while (en.hasMoreElements()) {
            String key = en.nextElement();
            String[] arr = httpServletRequest.getParameterValues(key);
            String value = "";
            if (arr != null && arr.length > 0) {
                value = arr[0] + "_change";
            }
//            System.out.println(key + "解密后：" + value);
            extraParams.put(key, value);
        }
        return true;
    }


    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
//        System.out.println("postHandle被调用");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
//        System.out.println("afterCompletion被调用");
    }
}